package jay.home.bet.test;

import sun.reflect.misc.FieldUtil;
import java.lang.reflect.Field;
import org.springframework.beans.BeanUtils;

public class Bean2HtmlInputTemplate
{
  protected static String nl;
  public static synchronized Bean2HtmlInputTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    Bean2HtmlInputTemplate result = new Bean2HtmlInputTemplate();
    nl = null;
    return result;
  }

  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "\t<tr><td><c:out value=\"${requestScope.event.";
  protected final String TEXT_2 = "}\"></td></tr>";
  protected final String TEXT_3 = NL + "\t<tr><td>";
  protected final String TEXT_4 = ".";
  protected final String TEXT_5 = ":<c:out value=\"${requestScope.event.";
  protected final String TEXT_6 = ".";
  protected final String TEXT_7 = "}\"></td></tr>";
  protected final String TEXT_8 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
Class bean = (Class)argument;
Field[] fields = FieldUtil.getDeclaredFields(bean);
for(Field field : fields)
{
  if(BeanUtils.isPrimitiveWrapper(field.getType()))
  {

    stringBuffer.append(TEXT_1);
    stringBuffer.append(field.getName());
    stringBuffer.append(TEXT_2);
    
  }
  else
  {
    Field[] fields2 = FieldUtil.getDeclaredFields(field.getType());
    for(Field item : fields2)
    {

    stringBuffer.append(TEXT_3);
    stringBuffer.append(field.getName());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(item.getName());
    stringBuffer.append(TEXT_5);
    stringBuffer.append(field.getName());
    stringBuffer.append(TEXT_6);
    stringBuffer.append(item.getName());
    stringBuffer.append(TEXT_7);
    
	}
  }
}

    stringBuffer.append(TEXT_8);
    return stringBuffer.toString();
  }
}
